package com.futures.questionbank.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.futures.questionbank.Constants.BaseBean;
import com.futures.questionbank.Constants.Constants;
import com.futures.questionbank.R;
import com.futures.questionbank.Utils.UItils;
import com.futures.questionbank.adapter.BaseViewHolder;
import com.futures.questionbank.adapter.SectionAdpter2;
import com.futures.questionbank.base.BaseFragment;
import com.futures.questionbank.db.table.zixun;
import com.futures.questionbank.http.CallBack;
import com.futures.questionbank.http.HttpClient;
import com.google.android.material.tabs.TabLayout;
import com.raizlabs.android.dbflow.sql.language.SQLite;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2020/6/15 0015 16:07
 * version: 1.0
 */
public class HeqingFragment extends BaseFragment {
    private RecyclerView rv;

    @BindView(R.id.tablayout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    private List<BaseFragment> fragments = new ArrayList<>();
    private List<String> tabs = new ArrayList<>();


    @Override
    protected int getLayoutResource() {
        return R.layout.information_fragment;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private void initView() {
        rv =  rootView.findViewById(R.id.rv);
        UItils.showDialog(getActivity());
        List<zixun > sections1 = SQLite.select().
                from(zixun.class).queryList();

        fragments.clear();
        tabs.clear();
        tabs.add("HuoBi");
        tabs.add("OKCoin");
        tabs.add("Bithumb");
        tabs.add("Bittrex");
        tabs.add("Bitstamp");
        tabs.add("Bitfinex");
        for (int i = 0; i < tabs.size(); i++) {
            fragments.add(new HangqingFragment2().newInstance(i));
        }



        //设置TabLayout的模式
        viewPager.setAdapter(new TabAdapter(getChildFragmentManager()));
        //关联ViewPager和TabLayout
        tabLayout.setupWithViewPager(viewPager);
      //  viewPager.setCurrentItem(position);
        //viewpaer一次加载全部页面
        viewPager.setOffscreenPageLimit(fragments.size());

    }

    class TypeItemListener implements BaseViewHolder.onItemCommonClickListener {
        @Override
        public void onItemClickListener(int position) {
            Intent intent = new Intent();
           // intent.putExtra("index", sections1.get(position).getExam_id());
           // intent.setClass(SectionActivity.this, ExamActivity.class);
            startActivity(intent);
        }

        @Override
        public void onItemLongClickListener(int position) {

        }
    }


    class TabAdapter extends FragmentPagerAdapter {
        public TabAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        //显示标签上的文字
        @Override
        public CharSequence getPageTitle(int position) {
            return tabs.get(position);
        }
    }
}
